<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\User;

class login extends Controller{
	
	//get请求
	// http://localhost/demo/TP5/thinkphp5/public/index.php/index/login/login
	public function login($user_name='',$user_passwd=''){
		  $request = request();
		  $user = User::get([
			'user_name' => $user_name,
			'UserPasswd' => $user_passwd
			]);
		 
		 if($user){
		    // echo '登录成功'.$user_name.md5($user_passwd);
			return json($user,200);
		}else{
			return json('登录失败',200);
			}
	}
	
	// 注册
	public function regist($user_name){
		$user = new User;
		 //接收前端表单提交的数据
		$user->user_name = $user_name;
		echo $user;
		//写入数据库
		if ($user->save()) {
		  // return $this->success('注册成功');
			return json('注册成功',200);
		} else {
			return json('注册失败',200);
		  // return $this->success('注册失败');
		}
	}
	// 查询成员列表
	public function members(){
		   $list = User::all(function($query){
            $query->limit(5)->order('user_id','asc');
			});
			return json($list,200);
	}
}

